//
//  MBProgressHUD+Extension.m
//  MiGuPlay
//
//  Created by Victor Chee on 16/4/12.
//  Copyright © 2016年 Migu. All rights reserved.
//

#import "MBProgressHUD+Extension.h"
#import "Utility.h"
@implementation MBProgressHUD(Extension)

+ (void)showTextHUD:(NSString *)text inView:(UIView *)view hideAfterDelay:(NSTimeInterval)delay {
    if ([Utility isValidString:text] && view && delay > 0) {
        dispatch_async(dispatch_get_main_queue(), ^{
            MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
            hud.mode = MBProgressHUDModeText;
            hud.removeFromSuperViewOnHide = YES;
            hud.label.text = text;
            hud.label.numberOfLines = 0;
            [hud hideAnimated:YES afterDelay:1];
        });
    }
}

+ (void)showTextHUD:(NSString *)text inView:(UIView *)view hideAfterDelay:(NSTimeInterval)delay completionHandler:(void (^)(void))completionHandler {
    if ([Utility isValidString:text] && view && delay > 0) {
        dispatch_async(dispatch_get_main_queue(), ^{
            MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
            hud.mode = MBProgressHUDModeText;
            hud.removeFromSuperViewOnHide = YES;
            hud.label.text = text;
            hud.label.numberOfLines = 0;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [hud hideAnimated:YES];
                __block typeof(completionHandler) block = completionHandler;
                if (block) {
                    block();
                    block = nil;
                }
            });
        });
    }
}





@end
